package com.supermap.geometry;

import com.supermap.geometry.service.GetDatasetGrpc;
import com.supermap.geometry.service.GetDatasetReply;
import com.supermap.geometry.service.GetDatasetRequest;
import com.supermap.grpc.*;
import com.supermap.protos.geometry.Dataset;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;

import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author liqs
 * @version 1.0
 * @date 2021/10/21 11:00
 */
public class GeometryClient {

    private static final Logger logger = Logger.getLogger(HelloWorldClient.class.getName());

    private final ManagedChannel channel;
    private final GetDatasetGrpc.GetDatasetBlockingStub getDatasetBlockingStub;

    /** Construct client connecting to HelloWorld server at {@code host:port}. */
    public GeometryClient(String host, int port) {

        channel = ManagedChannelBuilder
                .forAddress(host, port) // 地址端口
                .usePlaintext()         // 启用 SSL 通信
                .build();
        /**
         * 根据实际需要构造
         */
        getDatasetBlockingStub = GetDatasetGrpc.newBlockingStub(channel);
    }

    public void shutdown() throws InterruptedException {
        channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
    }

    public GetDatasetGrpc.GetDatasetBlockingStub getGetDatasetBlockingStub() {
        return getDatasetBlockingStub;
    }
}
